package com.suse.ecommerce.controller;

import com.suse.ecommerce.pojo.Store;
import com.suse.ecommerce.pojo.User;
import com.suse.ecommerce.service.StoreService;
import com.suse.ecommerce.uilts.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RequestMapping("/admin")
@RestController
public class StoreController {
    @Autowired
    private StoreService storeService;
    @RequestMapping("/storeLogin")
    public Msg storeLogin(@RequestParam(value="storeNick")String storeNick,
                     @RequestParam(value="password")String password, HttpServletRequest request){
        Store store = storeService.checkAdminLogin(storeNick,password);
        HttpSession session = request.getSession();
        if(store!=null){
            session.setAttribute("store",store);
            return Msg.success("登录成功");
        }else{
            return Msg.error("登录失败，用户名或者密码错误");
        }
    }
}
